﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vds2465Telegrams;

namespace Vds2465Parser
{
	internal static class GenParse_UserData_62_SourceNetAddress
	{
		#region internal methods

		internal static byte[] GenerateBytes(UserData userData)
		{
			if (userData is UserData_62_SourceNetAddress)
			{
				UserData_62_SourceNetAddress userData62 = userData as UserData_62_SourceNetAddress;
				return GenParse_UserData_AsciiBytes.GenerateBytes(UserData.UserData62SourceNetAddress, userData62.GetCopyOfAsciiBytes(), UserData_62_SourceNetAddress.MaxNrOfChars);
			}

			// TODO handle error - wrong UserData type
			byte[] userDataBytes = null;

			return userDataBytes;
		}

		internal static bool ParseBytes(byte[] userDataBytes, out UserData userData62SourceNetAddress, out int consumedBytes)
		{
			userData62SourceNetAddress = null;
			consumedBytes = 0;
			byte[] sourceNetAddressBytes;

			bool bRetVal = GenParse_UserData_AsciiBytes.ParseBytes(userDataBytes, UserData.UserData62SourceNetAddress, out sourceNetAddressBytes, out consumedBytes);
			if (bRetVal)
			{
				userData62SourceNetAddress = new UserData_62_SourceNetAddress(sourceNetAddressBytes);
			}

			return bRetVal;
		}

		#endregion internal methods
	}
}
